<?php

	use Doctrine\Common\ClassLoader,
	    Doctrine\ORM\Configuration,
	    Doctrine\ORM\EntityManager,
	    Doctrine\Common\Cache\ApcCache,
	    Procesos\Cargador\Organizacion\OrganizacionHandler,
		Procesos\Cargador\Organizacion\Cargador;
	$dirBase = __DIR__.'/..';
	$dirDoctrine = $dirBase.'/../doctrine-orm';

	
	require_once realpath($dirDoctrine .'/Doctrine/Common/ClassLoader.php');
	
	$classLoader = new \Doctrine\Common\ClassLoader('Doctrine\ORM', realpath($dirDoctrine));
	$classLoader->register();
	$classLoader = new \Doctrine\Common\ClassLoader('Doctrine\DBAL', realpath($dirDoctrine));
	$classLoader->register();
	$classLoader = new \Doctrine\Common\ClassLoader('Doctrine\Common', realpath($dirDoctrine));
	$classLoader->register();
	$classLoader = new \Doctrine\Common\ClassLoader('Symfony', realpath($dirDoctrine.'/Doctrine'));
	$classLoader->register();
	$classLoader = new \Doctrine\Common\ClassLoader('Entidades', $dirBase.'/Proyecto');
	$classLoader->register();
	$classLoader = new \Doctrine\Common\ClassLoader('Proxies', $dirBase.'/Proyecto');
	$classLoader->register();
	$classLoader = new \Doctrine\Common\ClassLoader('Procesos',$dirBase.'/Proyecto');
	$classLoader->register();

	$config = new Configuration;
	
	
	$cache = new ApcCache;
	
	$config->setMetadataCacheImpl($cache);
	
	
	$driverImpl = $config->newDefaultAnnotationDriver(array(__DIR__."/Proyecto/Entidades"));
	$config->setMetadataDriverImpl($driverImpl);
	$config->setQueryCacheImpl($cache);
	
	
	// Proxy configuration
	$config->setProxyDir($dirBase. '/Proyecto/Proxies');
	$config->setProxyNamespace('Proxies');
	$config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache);
	$config->setAutoGenerateProxyClasses((APPLICATION_ENV == "development"));
	
	
	$connectionOptions = array(
		    'driver' => 'pdo_mysql',
		    'dbname' => 'workflow',
		    'user' => 'p2a',
		    'password' => 'p2a',
		    'host' => 'localhost');
	
	// Create EntityManager
	
	$em = EntityManager::create($connectionOptions, $config);

	
	$cargador = new Cargador();
	
	include_once __DIR__.'/organizacion.php';
	
	foreach ($listaOrganizacion as $fileOrganizacion) {
		$cargador->xmlFromToDBOrganisacion($fileOrganizacion, $em);
	}
	print "Ahora ya termino \n";
	?>